/*
 * This file (AxIntParameter.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package artx.parameters;

import artx.utils.AxLog;

/**
 * Integer parameter class.
 * 
 * @author Xavier Gouchet
 * 
 */
public class AxIntParameter extends AxParameter {

	/** float value of the parameter */
	protected int intValue;

	/**
	 * Standard constructor.
	 * 
	 * @param name
	 *            name of the parameter
	 */
	public AxIntParameter(String name) {
		super(name, "int");
	}

	/**
	 * Standard constructor.
	 * 
	 * @param name
	 *            name of the parameter
	 * @param reset
	 *            default value of the parameter
	 */
	public AxIntParameter(String name, String reset) {
		super(name, "int", reset);
	}

	/**
	 * Get the integer value of the parameter.
	 * 
	 * @return integer value of the parameter
	 */
	public int GetValue() {
		return this.intValue;
	}

	/**
	 * @see artx.parameters.AxParameter#UpdateValue()
	 */
	public boolean UpdateValue() {
		if ((this.strValue == null) || (this.strValue.isEmpty())) {
			this.intValue = 0;
			return true;
		}
		try {
			int val = Integer.valueOf(this.strValue);
			this.intValue = val;
			return true;
		} catch (NumberFormatException e) {
			AxLog.Error("Can't convert parameter " + this.NAME + "'s value \""
					+ this.strValue + "\" to int");
			return false;
		}
	}

}
